﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPF_DbCenter.SqlServer.DataExchange
{
    /// <summary>
    /// Interaction logic for SyncDataInSqlServer.xaml
    /// </summary>
    public partial class SyncDataInSqlServer : Page
    {
        public SyncDataInSqlServer()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            string server = txtServername.Text;
            string database = this.txtDbName.Text;
            string username = this.txtUsername.Text;
            string pwd = passwordBox1.Password;
            bool isTrustedConn = (bool)chkIsTrustedConn.IsChecked;
            bool isSql05Express = (bool)chkIsSql05Expresss.IsChecked;

            if (string.IsNullOrEmpty(server) || string.IsNullOrEmpty(database)
                || string.IsNullOrEmpty(username))
            {
                MessageBox.Show("Please input each element");
                return;
            }


            CoreEA.ICoreEAHander core = new CoreEA.CoreE(CoreEA.CoreE.UsedDatabaseType.SqlServer).X_Handler;
            CoreEA.LoginDbInfo info = new CoreEA.LoginDbInfo(server, database, "", username, pwd);
            if (isSql05Express)
            {
                info.CurSqlServerVersion = CoreEA.LoginDbInfo.SqlServerVersionCollection.SqlServer2005Express;
            }
            info.IsTrustedConn = (bool)chkIsTrustedConn.IsChecked;
            try
            {
                core.Open(info);
                if (core.IsOpened)
                {
                    SrcTableList tableUI = new SrcTableList(core);

                    this.NavigationService.Navigate(tableUI);
                }
            }
            catch (Exception ee)
            {
                XLCS.Common.ProcessException.DisplayErrors(ee);
            }

        }
    }
}
